Skip to content

refactor: migrate from Tornado/requests to FastAPI/httpx#33

Merged
haobibo merged 16 commits into
mainfrom
dev/svc
Jun 24, 2026
Merged

refactor: migrate from Tornado/requests to FastAPI/httpx#33
haobibo merged 16 commits into
mainfrom
dev/svc

Conversation

@haobibo

@haobibo haobibo commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

This PR migrates the aloha package's service layer from Tornado + requests to FastAPI + httpx for better async support and modern web framework.

Key Changes

  • Replaced Tornado with FastAPI: The web.py and app.py modules now use FastAPI instead of Tornado for the web application framework
  • Replaced requests with httpx: HTTP client operations now use httpx for better async support
  • Updated base handlers: base_api_handler.py updated for FastAPI request handling
  • Updated HTTP client: base_api_client.py now uses httpx.AsyncClient with proper retry support
  • Updated file handling: files.py uses httpx for file downloads
  • API versions: Updated v0, v1, v2 modules to work with FastAPI routing
  • Uvicorn: Service now runs using uvicorn ASGI server

Backward Compatibility

The changes maintain backward compatibility for existing handler class patterns. The src/example programs should work with minimal changes - mainly ensuring service modules are registered in the configuration.

Dependencies

The setup.py already includes fastapi and httpx in the service dependencies:

"service": ["requests", "tornado", "psutil", "pyjwt", "fastapi", "httpx"],

Testing

The service was tested with:

  • GET requests: curl http://localhost:8888/api/common/sys_info
  • GET with parameters: curl http://localhost:8888/api/common/sys_info?kind=cpu
  • GET with path parameter: curl http://localhost:8888/api/common/sys_info/cpu
  • POST requests with JSON body

All tests passed successfully.

@haobibo can click here to continue refining the PR

This commit migrates the aloha package's service layer from Tornado + requests
to FastAPI + httpx for better async support and modern web framework.

Key changes:
- Replaced Tornado web.Application with FastAPI
- Replaced requests library with httpx for HTTP client operations
- Updated base_api_handler.py for FastAPI request handling
- Updated base_api_client.py to use httpx.AsyncClient
- Updated files.py to use httpx for file downloads
- Updated API v0, v1, v2 modules to work with FastAPI
- Updated app.py to use uvicorn for running the service
- Updated web.py to register routes from handler classes
- Maintained backward compatibility for existing handler class patterns
- Updated src example code (api_common_sys_info.py) to work with new framework

The src/example programs should work with minimal changes, mainly ensuring
the service modules are registered in the configuration.
@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ haobibo
❌ openhands-agent
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread pkg/aloha/service/api/v2.py Fixed
Comment thread pkg/aloha/service/http/base_api_handler.py Fixed
Comment thread pkg/aloha/service/api/v1.py Fixed
Comment thread pkg/aloha/service/api/v0.py Fixed
Comment thread pkg/aloha/service/api/v2.py Fixed
Comment thread pkg/aloha/service/web.py Fixed
Comment thread pkg/aloha/service/web.py Fixed
Comment thread pkg/aloha/service/app.py Fixed
Comment thread pkg/aloha/service/api/v1.py Fixed
Comment thread pkg/aloha/service/api/v0.py Fixed
Comment thread pkg/aloha/service/api/v0.py Fixed
Comment thread pkg/aloha/service/app.py Fixed
openhands-agent and others added 2 commits June 23, 2026 21:08
- Removed tornado and requests from service dependencies in setup.py
- Added uvicorn to service dependencies (required for running FastAPI)
- Updated src/requirements.txt to match the new dependencies
…eption''

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Signed-off-by: Bibo Hao <haobibo@users.noreply.github.com>
Comment thread pkg/aloha/service/http/base_api_client.py Fixed
content = data
else:
content = json.dumps(data, ensure_ascii=False, default=str, separators=(",", ":"))
return Response(content=content, status_code=status_code, media_type="application/json")
Comment thread pkg/aloha/service/api/v1.py Fixed
Comment thread pkg/aloha/service/api/v0.py Fixed
Comment thread pkg/aloha/service/api/v0.py Fixed
except Exception as e:
handler.LOG.error(e, exc_info=True)
msgs = ["An internal error has occurred.", str(e)]
return JSONResponse({"status": "error", "message": msgs}, status_code=500)
Comment thread pkg/aloha/db/mongo.py
}
LOG.debug(_config)
msg = {k: ("***" if k == "password" else v) for k, v in _config.items()}
LOG.debug(msg)
@haobibo haobibo merged commit 1daf1f2 into main Jun 24, 2026
8 of 9 checks passed
@haobibo haobibo deleted the dev/svc branch June 24, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants